import aes from 'crypto-js/aes';
import CryptoJS from 'crypto-js';
import secret from '../../../../utils/secret';

const getDecrypt = (params, secrets) =>
    JSON.parse(
        aes
            .decrypt(params, CryptoJS.enc.Utf8.parse(secrets), {
                iv: CryptoJS.enc.Utf8.parse(secrets),
                mode: CryptoJS.mode.CBC,
                padding: CryptoJS.pad.Pkcs7
            })
            .toString(CryptoJS.enc.Utf8)
    );

const checkConfig = request => {
    const params = request?.body?.params ? getDecrypt(request.body.params, secret) : null;

    console.log('queryTemplateProcessModel params', params);

    return {
        code: 10000,
        data: true
    };
};

export default {
    'GET x/api/finance/salary/v1/salaryTemplate/checkConfig': (req, res) => {
        res.json(checkConfig(req));
    }
};
